This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
Baskets <- read_excel("~/Desktop/Book4.xlsx")
## New names:
## • `` -> `...18`
b1 <- Baskets[,c("Neighborhood", "Banana")]
b1$Product <- "Banana"
b1$Cost <- b1$Banana
bf1 <- b1[,c("Neighborhood", "Product", "Cost")]
b2 <- Baskets[,c("Neighborhood", "Spaghetti")]
b2$Product <- "Spaghetti"
b2$Cost <- b2$Spaghetti
bf2 <- b2[,c("Neighborhood", "Product", "Cost")]
b3 <- Baskets[,c("Neighborhood", "Broccoli")]
b3$Product <- "Broccoli"
b3$Cost <- b3$Broccoli
bf3 <- b3[,c("Neighborhood", "Product", "Cost")]
b4 <- Baskets[,c("Neighborhood", "Eggs")]
b4$Product <- "Eggs"
b4$Cost <- b4$Eggs
bf4 <- b4[,c("Neighborhood", "Product", "Cost")]
b5 <- Baskets[,c("Neighborhood", "Milk")]
b5$Product <- "Milk"
b5$Cost <- b5$Milk
bf5 <- b5[,c("Neighborhood", "Product", "Cost")]
b6 <- Baskets[,c("Neighborhood", "Organic Milk")]
b6$Product <- "Organic Milk"
b6$Cost <- b6$'Organic Milk'
bf6 <- b6[,c("Neighborhood", "Product", "Cost")]
b7 <- Baskets[,c("Neighborhood", "Chicken Breast")]
b7$Product <- "Chicken Breast"
b7$Cost <- b7$'Chicken Breast'
bf7 <- b7[,c("Neighborhood", "Product", "Cost")]
b8 <- Baskets[,c("Neighborhood", "Cheerios")]
b8$Product <- "Cheerios"
b8$Cost <- b8$Cheerios
bf8 <- b8[,c("Neighborhood", "Product", "Cost")]
b9 <- Baskets[,c("Neighborhood", "Sirloin")]
b9$Product <- "Sirloin"
b9$Cost <- b9$Sirloin
bf9 <- b9[,c("Neighborhood", "Product", "Cost")]
b10 <- Baskets[,c("Neighborhood", "Basket Cost: Organic")]
b10$Product <- "Basket Cost: Organic "
b10$Cost <- b10$'Basket Cost: Organic'
bf10 <- b10[,c("Neighborhood", "Product", "Cost")]
b11 <- Baskets[,c("Neighborhood", "Basket Cost: Regular")]
b11$Product <- "Basket Cost: Regular"
b11$Cost <- b11$'Basket Cost: Regular'
bf11 <- b11[,c("Neighborhood", "Product", "Cost")]
bl <- rbind(bf1, bf2, bf3, bf4, bf5, bf6, bf7, bf8, bf9, bf10, bf11)
bl$Cost <- as.numeric(bl$Cost)
## Warning: NAs introduced by coercion
bl <- na.omit(bl)
bl$Neighborhood <- ifelse(bl$Neighborhood=="summersville, WV", "Summersville, WV", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="St. Louis", "St. Louis, MO", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="Sanford", "Sanford, FL", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="Lake Oswego", "Lake Oswego, OR", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="Detroit", "Detroit, MI", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="Cypress", "Cypress, TX", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="Cannon Falls", "Cannon Falls, MN", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="Boulder", "Boulder, CO", bl$Neighborhood)
bl$Neighborhood <- ifelse(bl$Neighborhood=="Billings", "Billings, MT", bl$Neighborhood)
bl <- bl[which(bl$Neighborhood!="Chicago"),]
g <- ggplot(bl, aes(x= Neighborhood, y=Cost, frame=Product, fill=Neighborhood)) +
geom_col(position="identity") +
ggtitle("Basket Cost") +
theme(plot.title=element_text(hjust = 0.5)) +
labs(y="Cost in $", x= "City") +
coord_flip()
ggplotly(g)
rsconnect::setAccountInfo(name = 'xdi18o-emily-mccollum',
token = '44C1F412E7EB2F39F2F10861D0B37DDD',
secret = 'bJYGbW5ItV26fu2rVF1COtsjIIJ10Yx3QMFymn0H',
server = 'posit.cloud')